/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.cef.api.attr.I18nResourceAttribute;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.method.CreateDataTypeGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.method.GetModelInfosMethodGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.property.BufferManagerPropertyGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.property.ChangesetPropGenerator;
import java.util.ArrayList;

public abstract class EntityManagerImplGenerator extends DataManagerImplGenerator {

  protected EntityManagerImplGenerator(ManagerGeneratorContext parContext) {
    super(parContext);
  }

  @Override
  protected final ArrayList<ClassPropertyGenerator> createPropertyGenerators() {

    ArrayList<ClassPropertyGenerator> propertyGenerators = super
        .createPropertyGenerators();

    if (propertyGenerators == null) {
      propertyGenerators = new ArrayList<ClassPropertyGenerator>();
    }

    BufferManagerPropertyGenerator bufferGenerator = getBufferPropGenerator();
    if (bufferGenerator != null) //TODO 后续去掉
    {
      propertyGenerators.add(bufferGenerator);
    }
    //protected abstract ChangesetManager ChangesetManager { get; }
    ChangesetPropGenerator changesetGenerator = getChangesetPropGenerator();
    if (changesetGenerator != null) //TODO 后续去掉
    {
      propertyGenerators.add(changesetGenerator);
    }

    addExtendPropertyGenerator(propertyGenerators);
    return propertyGenerators;
  }

  @Override
  protected final void addExtendMethodGenerator(
      ArrayList<ClassMethodGenerator> generators) {
    //国际化-判断设计时已生成MgrInfo标签，运行时生成国际化相关
//    if (ParentContext.getProjContext().getI18nModelInfoType() != null) {
//      generators.add(new GetModelInfosMethodGenerator(ParentContext));
//    }
    addExtendEntityMethodGenerator(generators);
  }

  @Override
  protected final CreateDataTypeGenerator getDataTypeGenerator() {
    return null;
  }

  protected void addExtendEntityMethodGenerator(
      ArrayList<ClassMethodGenerator> generators) {
  }

  protected void addExtendPropertyGenerator(
      ArrayList<ClassPropertyGenerator> generators) {
  }

  protected abstract BufferManagerPropertyGenerator getBufferPropGenerator();

  protected abstract ChangesetPropGenerator getChangesetPropGenerator();

  @Override
  protected ArrayList<BaseGenerator> createClassExtendChildGenrators() {
    ArrayList<BaseGenerator> list = super.createClassExtendChildGenrators();
    if (list == null) {
      list = new ArrayList<BaseGenerator>();
    }
    //i18n
    addModelResourceInfoGenenerator(list);
    return list;
  }

  private void addModelResourceInfoGenenerator(ArrayList<BaseGenerator> list) {
    //读取标签
//    I18nResourceAttribute modelResInfoAttr = ParentContext.getProjContext().getI18nModelInfoType();
//    if (modelResInfoAttr == null) {
//      return;
//    }
//    list.add(new ModelResourceInfoGenerator(modelResInfoAttr.resourceInfoType(), ParentContext));
  }
}
